<%@page import="cn.edu.nju.ws.sview.wyge.relations.datasets.DatasetItem"%>
<%@page import="cn.edu.nju.ws.sview.rdf.URIResource"%>
<%@page import="cn.edu.nju.ws.sview.wyge.servlets.Dataset"%>
<%@page import="cn.edu.nju.ws.sview.views.Group"%>
<%@page
	import="cn.edu.nju.ws.sview.wyge.relations.adataset.comment.AllComments"%>
<%@page
	import="cn.edu.nju.ws.sview.wyge.relations.adataset.VisitDataset"%>
<%@page import="cn.edu.nju.ws.sview.wyge.relations.adataset.LikeDislike"%>
<%@page
	import="cn.edu.nju.ws.sview.wyge.relations.adataset.DocumentDataset"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@page
	import="cn.edu.nju.ws.sview.wyge.relations.adataset.CustomDataset"%>
<%@page
	import="cn.edu.nju.ws.sview.wyge.relations.adataset.comment.DatasetComment"%>
<%@page import="java.net.URLEncoder"%>
<%@page import="cn.edu.nju.ws.sview.wyge.util.Util"%>
<%@page import="cn.edu.nju.ws.sview.cache.*"%>
<%@page import="java.util.Enumeration"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page
	import="java.util.Map.Entry,java.util.ArrayList,java.util.HashSet,java.util.HashMap"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Dataset Detail</title>
  </head>
 <link rel="icon" href="/sview/favicon.ico" />
<link rel="stylesheet" type="text/css" href="/sview/css/layout.css" />
<link rel="stylesheet" type="text/css"
	href="/sview/css/smoothness/jquery-ui-1.8.16.custom.css" />
<link rel="stylesheet" type="text/css" href="/sview/css/easyui.css" />
<link rel="stylesheet" type="text/css" href="/sview/css/relations/ds_detail.css" />
<script type="text/javascript" src="/sview/script/jquery.js"></script>
<script type="text/javascript" src="/sview/script/jquery.easyui.min.js"></script>
<script type="text/javascript" src="/sview/script/jquery-ui-1.8.16.custom.min.js"></script>
<script type="text/javascript" src="/sview/script/relations/ds_detail.js"></script>
<script type="text/javascript" src="/sview/script/global.js"></script>
<script type="text/javascript" src="/sview/script/relations/URILocalname.js"></script>
<script type="text/javascript" src="/sview/script/relations/jquery.cookie.js"></script>
  <body>
  <%
		String lang = request.getParameter("lang");
		if (lang != null && lang.equals("zh")) {
			request.getRequestDispatcher("ds_detail_zh.jsp").forward(
					request, response);
			return;
		} else if (lang == null) {
			lang = "en";
		}
		String ugname = (String)session.getAttribute("groupName");
		int ugid = -1;
		if(ugname != null){
			ugid = Group.getGroupIdByName(ugname);
		}		
		String ds_type = request.getParameter("ds_type");
		String dsIdStr = request.getParameter("ds_id");
		int datasetId = 0;
		if (dsIdStr == null) {
			String location = "/sview/relations/index.jsp";
			if (lang.equals("zh"))
				location = location + "?lang=" + lang;
			response.sendRedirect(location);
			return;
		} else {
			datasetId = Integer.parseInt(dsIdStr);
		}
		int gid = -1;
		String gname = null;
		String user = (String)session.getAttribute("user");
	%>

<div class="container">
		<div class="generalInfo">
			<div class="general_info">
				<div id="title" class="general-info-title">
					<%
						String name = DatasetItem.getShowNameByDatasetID(datasetId, ds_type, lang);
						if (ds_type.contentEquals("custom")) {
							//name = CustomDataset.getNameByCustomDatasetID(datasetId);
							gname = (String)CustomDataset.getGroupByCustomDatasetId(datasetId);
							gid = Group.getGroupIdByName(gname);
						//} else if (ds_type.contentEquals("uri")) {
						//	try {
						//		//name = URIIDCache.getInstance().getURI(datasetId);
						//		name = URIResource.getLabel(datasetId, lang);
						//	} catch (Throwable e) {
						//		e.printStackTrace();
						//	}
						}
					%>
					<div class="titlename relative">
						<span class="entity-label" id="dsname" title="<%=name%>" ds_type="<%=ds_type %>" datasetId="<%=datasetId %>" ><%=Util.trimString(name, 50)%></span>
					</div>
				</div>
				<div class="mspacingLittle"></div>
				<div class="metadata">
					<%
						if (ds_type.contentEquals("custom")) {
					%>
					Editing Group:&nbsp;&nbsp;&nbsp;<span><a href="/sview/group/gprofile.jsp?gid=<%=gid%>&uname=<%=user%>"><%=gname %></a></span><br />
					Latest Update:&nbsp;&nbsp;&nbsp;<span><%=CustomDataset.getCreatedDateByCustomDatasetID(datasetId, "yyyy/MM/dd")%></span><br /> 
					<%
						}
					%>
				</div>
				
			</div>
		</div>
		<%if (ds_type.contentEquals("custom")) {%>
		<div class="docs">
			<span class="title">Rdf Documents</span>
			<div class="centity-list  entity-list"></div>
		</div>
		<%} else{
		try {
			String uri = URIIDCache.getInstance().getURI(datasetId);
			String href = "/sview/dataset/u"+datasetId;//"/sview/o"+datasetId;
		%>
		<div class="docs">
			<span class="title">Source</span>
			<div class="uentity-list  entity-list"><ul><li><a href="<%=href %>"><%=uri %></a></li></ul></div>
		</div>
		<%} catch (Throwable e) {
				e.printStackTrace();
			}
		} %>
		<div class="commentBox">
					<%
						String comment = null;
						ArrayList<DatasetComment> commentArray = null;
						if(ds_type.contentEquals("uri")){
							comment = DatasetComment.getUriDescription(datasetId, lang);//.getOriginComment(datasetId, lang);
							if(comment != null && comment.length()>0){
						%>
					<span class="title">描述</span>
					<div class="comment-box">
						<%=comment%>
					</div>
					<%
						}
					}else if(ds_type.contentEquals("custom")){
						comment = DatasetComment.getCustomDescription(datasetId, lang);
							//commentArray = DatasetComment.getCommentsByDatasetLangUserOrderByTime(ds_type, datasetId, lang, null, 0, 1);
								//.getCommentsByDatasetLangUserOrderByScore(ds_type, datasetId, lang, null, 0, 1);
						//if(commentArray.size()>0){%>
					<span class="title">描述</span>
					<%}
						//for (DatasetComment dc : commentArray) {
						//	comment = dc.getText();
						//	SimpleDateFormat df = new SimpleDateFormat("MM/dd, yyyy");
						//	String date = df.format(dc.getTime());
					%>
					<div class="comment-box">
						<%=comment%>
					<%-- <span class="commentMeta">——by <b><%=dc.getAuthor()%></b> on <b><%=date%></b></span> --%>
					</div>
					<%
						//}//end of for
						//}
					%>
		</div>
		<div id="catalog" class="catalog">
			<div id="treeDiv">
			<span class="title">Classes</span>
				<div class="tree">
					<ul id="namedEntitiesUl"></ul> 
					<ul id="othersUl"></ul>
				</div>
			</div>
		</div>
		<div class="content">
			<span class="title">Content</span>
			<div id="entitiesDiv"></div>
			<div class="backDiv"><a href="#title">Top</a></div>
		</div>
		<div id="onloading" class="section">
			<div style="text-align: center">
				<p>&nbsp;</p>
				<p>Loading Data, Please Wait...</p>
			</div>
		</div>
	</div>
	<input type="hidden" id="display-lang" value="en" />
<input type="hidden" id="ds_type" value="<%=ds_type%>" />
<input type="hidden" id="ds_id" value="<%=datasetId%>" />
<jsp:include page="/vfooter.jsp"></jsp:include>
  </body>
</html>
